package com.example.compositionlocals

import androidx.compose.foundation.layout.Column
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.sp

var LocalString = compositionLocalOf { "Jetpack Compose" }
var LocalFontSize = compositionLocalOf { 17.sp }

@Composable
fun compositionLocalText() {
    Column {
        CompositionLocalProvider(
            LocalString provides "Hello World",
            LocalFontSize provides 25.sp
        ) {
            Text(
                text = LocalString.current,
                color = Color.Red,
                fontSize = LocalFontSize.current
            )

            CompositionLocalProvider(
                LocalString provides "My favorite is Android",
                LocalFontSize provides 20.sp
            ) {
                Text(
                    text = LocalString.current,
                    color = Color.Green,
                    fontSize = LocalFontSize.current
                )
            }
        }
        Text(
            text = LocalString.current,
            color = Color.Blue,
            fontSize = LocalFontSize.current
        )
    }
}